package com.test.io.buffer;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @version 1.0
 * @Author: 许啸林  包装流bufferReader的练习
 * @Date: 2021/6/2 15:47
 */
public class BufferReaderDemo {
        // 从指定文件中读取数据
        @Test
        public void ReadFile() {
            BufferedReader bufferedReader = null;
            try {
                // 处理流 提供了对 ioStream 字符流 活 Reader 的进一步方法封装
                bufferedReader =  new BufferedReader(new FileReader("d:\\newFile2.text"));
                String str = "";
                while ((str = bufferedReader.readLine()) != null) {
                    System.out.println(str);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        }
}
